package cqqspringcloud.Controller;

import com.cqqspringcloud.entiy.Payment;

import cqqspringcloud.service.PaymentService;
import cqqspringcloud.util.CommentResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {
    @Resource
    private PaymentService paymentService;
     @Value("${server.port}")
    private String serverport;
    @RequestMapping(value = "/add",method = RequestMethod.PATCH)
    public CommentResult create(@RequestBody Payment payment){
        int result = paymentService.create(payment);
        log.info("*******插入结果"+result);
        System.out.println("result = " + result);
        if (result>0){
        return new CommentResult(200,"插入数据成功,serverport"+serverport,result);
        }else{
            return new CommentResult(500,"插入数据失败",null);
        }

    }

   @GetMapping("/getOne/{id}")
    public CommentResult  getPayMentbyId(@PathVariable("id") Long  id){
        Payment result = paymentService.getPaymentbyId(id);
        log.info("*******查询结果"+result);
       System.out.println("result = " + result);
        if (result!=null){
            return new CommentResult(200,"查询成功,serverport"+serverport,result);
        }else{
            return new CommentResult(500,"查询失败",null);
        }

    }

}
